package com.bwie.controller;

import cn.hutool.core.lang.Validator;
import com.bwie.service.UserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginVo;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.RegInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: tsh
 * @Date: 2025/7/18 11:25
 * @Description:
 **/
@RestController
@RequestMapping("/auth/index")
@Api(tags = "认证微服务")
public class IndexController {

    @Autowired
    UserService userService;

    /**
     * @param mobile
     * @return com.bwie.utils.R
     * @description sendMobile  发送验证码
     * * @params
     * @author tsh
     * @date 2025/7/18 11:38
     */
    @PostMapping("/sendCode/{mobile}")
    @ApiOperation(value = "发送验证码")
    public R sendCode(@PathVariable("mobile") String mobile) {
        boolean b = Validator.isMobile(mobile);
        if(!b){
            return R.ERROR(500,"手机号错误");
        }
        return userService.sendCode(mobile);
    }

    /**
     * @description userReg 用户注册
     * @params
     * @param regInfoVo
     * @return com.bwie.utils.R
     * @author tsh
     * @date 2025/7/18 11:45
     */
    @PostMapping("/userReg")
    @ApiOperation(value = "用户注册")
    public R userReg(@RequestBody @Validated RegInfoVo regInfoVo) {
        return userService.userReg(regInfoVo);
    }

    /**
     * @description
     * @params
     * @return com.bwie.utils.R
     * @author tsh
     * @date 2025/7/18 14:05
     */
    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public R login(@RequestBody @Validated LoginVo loginVo){
        return userService.login(loginVo);
    }

    /**
     * @description 获取当前用户菜单树
     * @params
     * @return com.bwie.utils.R
     * @author tsh
     * @date 2025/7/20 19:41
     */
    @PostMapping("/getMenuTree")
    @ApiOperation(value = "获取当前用户菜单树")
    public R getMenuTree(){
        return userService.getMenuTree();
    }

    @PostMapping("/getMenu")
    @ApiOperation(value = "递归获取菜单")
    public R getMenu(){
        return userService.getMenu();
    }
    @PostMapping("/getShopperList")
    @ApiOperation(value = "商家列表")
    public R getShopperList(@RequestBody PageInfoVo pageInfoVo){
        return userService.getShopperList(pageInfoVo);
    }


}
